package com.wanpinghui.supplier.utils;

import com.yunshl.yunshllibrary.utils.TimeUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/***
 * 功能描述:
 * 作者:qiujialiu
 * 时间:2017/11/24
 ***/

public class WTimeUtil {

    public static boolean isOneMinus(long preTime, long curTime) {
        long time = curTime - preTime;
        if (time < 60000) {
            return true;
        } else {
            return false;
        }
    }

    public static String getRecentChatTime(long timeSecond) {
        // long time = System.currentTimeMillis() - timeSecond;
        if (TimeUtil.getBetweenDay(System.currentTimeMillis(), timeSecond) >= 1) {
            return TimeUtil.format(timeSecond, "yyyy-MM-dd");
        } else {
            return TimeUtil.format(timeSecond, "HH:mm");
        }
    }



    public static String getChatTime(long timeSecond){
            //   long time = System.currentTimeMillis() - timeSecond;
            if (TimeUtil.getBetweenDay(System.currentTimeMillis(), timeSecond) >= 1) {
                return TimeUtil.format(timeSecond, "yyyy-MM-dd HH:mm");
            } else {
                return TimeUtil.format(timeSecond, "HH:mm");
            }
        }

    public static String getTimeShowStr(long timeSecond) {
        long time = System.currentTimeMillis() - (timeSecond * 1000);
        if (time < 60000) {
            return "1分钟前";
        } else {
            if (time < 1000 * 60 * 60) {
                return (time / 60000) + "分钟前";
            } else if (time < (1000 * 60 * 60 * 24)) {
                return (time / (60000 * 60)) + "小时前";
            } else if (time < (1000 * 60 * 60 * 24 * 7)) {
                return (time / (60000 * 60 * 24)) + "天前";
            }
        }
        return TimeUtil.format(timeSecond * 1000, "yyyy-MM-dd");
    }

    public static String getRecordTimeStr(int seconds) {
        if (seconds < 0) {
            return "";
        }
        if (seconds < (60 * 60)) {
            return TimeUtil.format(seconds * 1000, "mm:ss");
        } else if (seconds < (60 * 60 * 24)) {
            return TimeUtil.format(seconds * 1000, "HH:mm:ss");
        } else {
            return (seconds / (60 * 60 * 24)) + "天";
        }
    }

    public static int getYear(long timeSeconds) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(timeSeconds * 1000);
        return calendar.get(Calendar.YEAR);
    }

    // 传入日期跟当前日期比较
    public static boolean compareCurrentDate(String date){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date mDate = null;
        Date mCurrentDate = null;
        try {
            mDate = simpleDateFormat.parse(date);
            mCurrentDate= simpleDateFormat.parse(simpleDateFormat.format(new Date()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        long mDateLong = mDate.getTime();
        long mCurrentDateLong = mCurrentDate.getTime();

        return mDateLong > mCurrentDateLong;
    }
}
